<?php
namespace TinyPHP\DB;
/*
 *
 * 基础Model类，所有的Model文件均继承本类
 * Created by tiny
 * User: tiny
 * Date: 16/06/23
 * E-mail: mountaingiant@163.com
 *
 * */
 class Model implements DbInterface{
     protected $dbConfigKey = null;
     private $_db = null;

     private function _getInstance(){
         if(is_null($this->_db)){
             if(is_null($this->dbConfigKey)){
                 $this->_db = Db::factor();
             }else{
                 $this->_db = Db::factor($this->dbConfigKey);
             }
         }
         return $this->_db;
     }

     public function close(){
         $this->_getInstance()->close();
     }

     public function query($sql){
         return $this->_getInstance()->query($sql);
     }

     public function fetchAssoc($resource){
         return $this->_getInstance()->fetchAssoc($resource);
     }

     public function select($sql){
         return $this->_getInstance()->select($sql);
     }
 }